layui.use(['form','jquery','layer','upload','laydate'],function () {
    var form = layui.form;
    var $ = layui.$;
    var layer = layui.layer;
    var upload = layui.upload;
    var laydate = layui.laydate;
    //开始时间渲染
    laydate.render({
        elem: '#startDate',
        type: 'datetime'
    });
    //到期时间渲染
    laydate.render({
        elem: '#expireDate',
        type: 'datetime'
    });

    //上传文件渲染
    upload.render({
        elem: '#uploadImage',
        url: '/JsCarousel/uploadImagesCarousel',
        accept: 'images',
        field: 'file',
        method: "post",
        exts: 'png|jpg|gif',
        done: function(res, index, upload){
            if(res.code == 0){
                layer.msg('上传成功');
                $('#imgAddress').val(res.data.data.src);
                $('#imgType').val(res.data.data.imgType);
                $('#currentImage').attr('src',res.data.data.src);
            }
        }
    });
    //更改按钮
    form.on('submit(sub)',function (obj) {
        $.ajax({
            url: '/JsCarousel/updateJsCarousel',
            data: obj.field,
            type: 'post',
            dataType: 'json',
            success: function (data) {
                layer.msg(data.data);

            }
        });
        var layer = parent.layer;
        layer.close(layer.index);
        return false;
    });
})